package org.idea.spring.condition.classinject;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

/**
 * @Author linhao
 * @Date created in 8:06 上午 2021/5/8
 */
public class LoadConfigApplication {

    @Autowired
    @Qualifier("pig1")
    public Pig pig1;

    @Autowired(required = false)
    @Qualifier("pig2")
    public Pig pig2;

    public static void main(String[] args) {
        AnnotationConfigApplicationContext annotationConfigApplicationContext = new AnnotationConfigApplicationContext();
        annotationConfigApplicationContext.register(LoadConfigApplication.class);
        annotationConfigApplicationContext.register(MyConfig.class);
        annotationConfigApplicationContext.refresh();
        LoadConfigApplication loadConfigApplication = annotationConfigApplicationContext.getBean(LoadConfigApplication.class);
        System.out.println(loadConfigApplication.pig1);
        System.out.println(loadConfigApplication.pig2);
        annotationConfigApplicationContext.close();
    }
}
